//
//  OrderListViewController.m
//  HaiGoumerMerchant
//
//  Created by apple on 17/1/17.
//  Copyright © 2017年 com.zaoguankeji.www. All rights reserved.
//

#import "OrderListViewController.h"
#import "OrderlistTableViewCell.h"

#import "OrderInfoTableViewController.h"

#import "SelectTimeView.h"

#import "YUSegment.h"
static   NSString * const kCelllistID = @"OrderlistTableViewCell";
static   NSString * const kCellHeaderID = @"OrderListHeaderTableViewCell";
static   NSString * const kCellFooterID = @"OrderListFooterTableViewCell";
@interface OrderListViewController ()<UITableViewDelegate, UITableViewDataSource, UITextFieldDelegate>
//@property (weak, nonatomic) IBOutlet UIView *selectTimeView;
//@property (weak, nonatomic) IBOutlet UIView *segmentStyleView;
@property (nonatomic, strong) SelectTimeView *segment;
@property (nonatomic, strong) UITableView *myTableView;


@property(nonatomic, strong) NSMutableArray *dataArr;


@end

@implementation OrderListViewController
#pragma mark -----------dataArr-------------------懒加载;
- (NSMutableArray *)dataArr{
    if (!_dataArr) {
        self.dataArr = [NSMutableArray array];
    }
    
    return _dataArr;
}

-(SelectTimeView *)segment {
    
    if (!_segment) {
        self.segment = [SelectTimeView new];
        [self.view addSubview:self.segment];
         self.segment.frame = CGRectMake(0, 0,WIDTH_SCREEN , HEIGHT_NAVBAR);
    }
    return  _segment;
}

- (void)configureSelectTimeView {
    
    
    
}
///MARK-- Search

#pragma mark ------------------------ 搜索框
- (void)setupSearch{
    
    UIView *searchView = [[UIView alloc] initWithFrame:CGRectMake(0, HEIGHT_NAVBAR, WIDTH_SCREEN, HEIGHT_NAVBAR)];
    searchView.backgroundColor = [UIColor colorWithRed:237/255.0 green:239/255.0 blue:240/255.0 alpha:1];
    
    UITextField *searchTF = [[UITextField alloc] initWithFrame:CGRectMake(10, 8, self.view.bounds.size.width - 10 * 2, 44 - 5*2)];
    searchTF.clearButtonMode = UITextFieldViewModeWhileEditing;
    UIImageView *rightView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"search"]];
    rightView.frame = CGRectMake(-20, 0, 30, searchTF.frame.size.height - 15);
    searchTF.rightView = rightView;
    searchTF.borderStyle = UITextBorderStyleRoundedRect;
    searchTF.backgroundColor = [UIColor whiteColor];
    searchTF.rightViewMode = UITextFieldViewModeUnlessEditing;
    searchTF.returnKeyType = UIReturnKeySearch;
    searchTF.placeholder = @"请输入关键词或手机号";
    [searchView addSubview:searchTF];
    searchTF.delegate = self;
    self.myTableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
    [self.view addSubview:searchView];
}
#pragma mark ------------------------ UItextfield
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    
    [textField resignFirstResponder];
    return  YES;
}

- (void)viewWillLayoutSubviews {
    
     self.segment.frame = CGRectMake(0, 300,WIDTH_SCREEN , HEIGHT_NAVBAR);
    [self.view addSubview:self.segment];
    [super viewWillLayoutSubviews];
}
- (void)configureSegmentStyleView {
   
    self.segment.frame = CGRectMake(0, 0,WIDTH_SCREEN , HEIGHT_NAVBAR);
//    [self.view addSubview:self.segment];
    
}

- (void)configureTableView {

    UITableView *tableView = [[UITableView alloc] initWithFrame:
                              CGRectMake(0, 2* HEIGHT_NAVBAR, self.view.frame.size.width, HEIGHT_SCREEN - 88 -44-20-44  ) style:(UITableViewStyleGrouped)];
    
    // 设置背景
    tableView.backgroundColor = [UIColor whiteColor];
    
    // 设置分割线的类型
    tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
    
    // 设置分割线颜色
//    tableView.separatorColor = [UIColor blackColor];
    
    // 设置分割线的位置
//    tableView.separatorInset = UIEdgeInsetsMake(0, 20, 0, 20);
    
    // 数据源和代理
    tableView.dataSource = self;
    tableView.delegate = self;
    
    self.myTableView = tableView;
    [self.view addSubview:self.myTableView];
//    [self.myTableView canResignFirstResponder];
    [self configureOrderListViewControllerTableView];
    
}
- (void)configureOrderListViewControllerTableView {
    self.myTableView.tableFooterView = [UIView new];
    self.myTableView.rowHeight = UITableViewAutomaticDimension;
    self.myTableView.estimatedRowHeight = 130;
    //    self.tableView.estimatedSectionFooterHeight = 100;
    self.myTableView.estimatedSectionHeaderHeight = 10;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationController.navigationBar.translucent = NO;
     self.title = @"订单列表";
    self.dataArr = @[@"44",@"55",@"44",@"55"];
//    self.dataArr = @[];
    self.view.backgroundColor = [UIColor whiteColor];
     [self setupSearch];
    [self configureSegmentStyleView];
    [self configureTableView];
    [self registerNibTableView];
    [self configureSelectTimeView];
    
   
    // Do any additional setup after loading the view.
}

- (void)registerNibTableView {
    [self.myTableView registerNib:[UINib nibWithNibName:kCelllistID bundle:nil] forCellReuseIdentifier:kCelllistID];
    [self.myTableView registerNib:[UINib nibWithNibName:kCellFooterID bundle:nil] forCellReuseIdentifier:kCellFooterID];
    [self.myTableView registerNib:[UINib nibWithNibName:kCellHeaderID bundle:nil] forCellReuseIdentifier:kCellHeaderID];
    

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return self.dataArr.count >0 ?  [tableView dequeueReusableCellWithIdentifier:kCellHeaderID] : nil;
    
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    return  self.dataArr.count >0 ?  [tableView dequeueReusableCellWithIdentifier:kCellFooterID] : nil;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 100;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 48;
}
//- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
//    return 100;
//}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
#warning Incomplete implementation, return the number of sections
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of rows
    return self.dataArr.count > 0 ? self.dataArr.count : 0;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    OrderListViewController *vc = [UIStoryboard loadStoryboard:OrderInfoTableViewControllerID];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    OrderlistTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCelllistID forIndexPath:indexPath];
    
    
    
    return cell;
}
@end
